<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>无人深空 - I am alone, but I don't feel lonely.</title><meta name="author" content="zcm"><meta name="copyright" content="zcm"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta property="og:type" content="website">
<meta property="og:title" content="无人深空">
<meta property="og:url" content="https://gitee.com/zcmmmm/zcmmmm/page/4/index.html">
<meta property="og:site_name" content="无人深空">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s2.loli.net/2022/09/22/36LN4kcjYOd9HT8.jpg">
<meta property="article:author" content="zcm">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s2.loli.net/2022/09/22/36LN4kcjYOd9HT8.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://gitee.com/zcmmmm/zcmmmm/page/4/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '无人深空',
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2023-05-18 19:46:06'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/categories.css?v1"><link rel="stylesheet" href="/css/navigation.css?v1"><link rel="stylesheet" href="/css/custom.css?v1"><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://s2.loli.net/2022/09/22/36LN4kcjYOd9HT8.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">43</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">无人深空</a></span><div id="menus"></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div><div id="nav-right"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i></a></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left"><a href="/2022/09/23/SpringMVC/" title="SpringMVC"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/Spring/Spring.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="SpringMVC"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/09/23/SpringMVC/" title="SpringMVC">SpringMVC</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-09-23T03:56:32.000Z" title="发表于 2022-09-23 11:56:32">2022-09-23</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Spring/">Spring</a></span></div><div class="content">SpringMVC一、SpringMVC简介1、什么是MVCMVC是一种软件架构的思想，将软件按照模型、视图、控制器来划分
M：Model，模型层，指工程中的 JavaBean，作用是处理数据
JavaBean分为两类：

一类称为实体类Bean：专门存储业务数据的，如 Student、User 等
一类称为业务处理 Bean：指 Service 或 Dao 对象，专门用于处理业务逻辑和数据访问

V：View，视图层，指工程中的 html 或 jsp 等页面，作用是与用户进行交互，展示数据
C：Controller，控制层，指工程中的 servlet，作用是接收请求和响应浏览器
MVC 的工作流程：用户通过视图层发送请求到服务器，在服务器中请求被 Controller 接收，Controller 调用相应的 Model 层处理请求，处理完毕将结果返回到 Controller，Controller 再根据请求处理的结果找到相应的 View 视图，渲染数据后最终响应给浏览器
2、什么是SpringMVCSpringMVC 是 Spring 的一个后续产品，是 Spring 的一个子项目
 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/09/23/Spring5%E6%A1%86%E6%9E%B6/" title="Spring5框架"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/Spring/Spring.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Spring5框架"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/09/23/Spring5%E6%A1%86%E6%9E%B6/" title="Spring5框架">Spring5框架</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-09-23T03:46:30.000Z" title="发表于 2022-09-23 11:46:30">2022-09-23</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Spring/">Spring</a></span></div><div class="content">Spring5 框架课程内容
Spring 框架概述
IOC 容器 
IOC 底层原理
IOC 接口（BeanFactory）
IOC 操作 Bean 管理（基于 xml）
IOC 操作 Bean 管理（基于注解）


Aop
JdbcTemplate
事务管理
Spring5 新特性

Spring5 框架概述
Spring 是轻量级的开源的 JavaEE 框架

Spring 可以解决企业应用开发的复杂性

Spring 有两个核心部分：IOC 和 Aop 

IOC：控制反转，把创建对象过程交给 Spring 进行管理
Aop：面向切面，不修改源代码进行功能增强


Spring 特点

方便解耦，简化开发
Aop 编程支持
方便程序测试
方便和其他框架进行整合
方便进行事务操作
降低 API 开发难度


Spring 入门

下载 Spring5 相关资源

创建 Java 工程，导入 Spring5 基本 jar 包

创建普通类
public class User &#123;    public void add() &#123;        System.out.p ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/09/23/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" title="设计模式"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/Design%20pattern.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="设计模式"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/09/23/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" title="设计模式">设计模式</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-09-23T03:04:08.000Z" title="发表于 2022-09-23 11:04:08">2022-09-23</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Others/">Others</a></span></div><div class="content">设计模式（design pattern）目标：高内聚、低耦合内聚（从高到低）：表示内部间聚集、关联的程度，那么高内聚就是指要高度的聚集和关联。高内聚是指类与类之间的关系而定，意思是他们之间的关系要简单明了，不要有很强的关系，不然运行起来就会出问题

功能内聚：模块内所有元素的各个组成部分全部都为完成同一个功能而存在，共同完成一个单一的功能，模块已不可再分。即模块仅包括为完成某个功能所必须的所有成分，这些成分紧密联系、缺一不可
顺序内聚：一个模块中各个处理元素和同一个功能密切相关，而且这些处理必须顺序执行，通常前一个处理元素的输出时后一个处理元素的输入。例如某要完成获取订单信息的功能，前一个功能获取用户信息，后一个执行计算均价操作，显然该模块内两部分紧密关联。顺序内聚的内聚度比较高，但缺点是不如功能内聚易于维护
通信内聚：指模块内所有处理元素都在同一个数据结构上操作或所有处理功能都通过公用数据而发生关联（有时称之为信息内聚）。即指模块内各个组成部分都使用相同的数据结构或产生相同的数据结构
过程内聚：构件或者操作的组合方式是，允许在调用前面的构件或操作之后，马上调用后面的构件或操作，即使两 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/09/23/Java-Web/" title="JavaWeb"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/JavaWeb/Java%20Web.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JavaWeb"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/09/23/Java-Web/" title="JavaWeb">JavaWeb</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-09-23T02:57:46.000Z" title="发表于 2022-09-23 10:57:46">2022-09-23</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span></div><div class="content">2022版JavaWeb教程（全新技术栈，全程实战）前端三件套
HTML：Hyper Text Markup Language（超文本标记语言）

HTML 是解释型的文本标记语言，不区分大小写

存储页面内容，本身是一种文本文件

常用标签

双标签：有开始标签和结束标签

&lt;html&gt; &lt;/html&gt;、&lt;head&gt; &lt;/head&gt;、&lt;body&gt; &lt;/body&gt;

&lt;hx&gt; &lt;/hx&gt; 标题

&lt;ol&gt; &lt;li&gt; &lt;/li&gt; &lt;/ol&gt; 有序列表：start 表示从 * 开始；type 显示类型有 A a I i 1(默认)

&lt;ol&gt; &lt;li&gt; &lt;/li&gt; &lt;/ol&gt; 有序列表：type 显示类型有 disc(默认)、circle、square

&lt;b&gt; &lt;/b&gt; 加粗

&lt;i&gt; &lt;/i&gt; 斜体

&lt;u&gt; &lt;/u&gt; 下划线 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/09/23/%E9%9B%B6%E5%9F%BA%E7%A1%80%E5%AD%A6-Java-03/" title="零基础学-Java-03"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/%E9%9B%B6%E5%9F%BA%E7%A1%80%E5%AD%A6Java/Cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="零基础学-Java-03"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/09/23/%E9%9B%B6%E5%9F%BA%E7%A1%80%E5%AD%A6-Java-03/" title="零基础学-Java-03">零基础学-Java-03</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-09-23T01:23:37.000Z" title="发表于 2022-09-23 09:23:37">2022-09-23</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span></div><div class="content">网络编程
在开发中尽量不要使用 0~1024 端口（2000 以内都别用）

客户端和服务端都有端口，客户端端口随机分配，服务器端口需指定

InetAddress 类：可序列化，实现了 Serializable

getLocalHost：获取本机 InetAddress 对象
getByName：根据指定主机名 &#x2F; 域名获取 ip 地址对象
getHostName：获取 InetAddress 对象的主机名
getHostAddress：获取 InetAddress 对象的地址

// 1.获取本机 InetAddress 对象InetAddress localHost = InetAddress.getLocalHost();System.out.println(localHost);      // LAPTOP-51JTTFR5/192.168.0.110// 2.根据指定主机名 ip 地址对象InetAddress host = InetAddress.getByName(&quot;LAPTOP-51JTTFR5&quot;);System.out.printl ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/09/23/%E9%9B%B6%E5%9F%BA%E7%A1%80%E5%AD%A6-Java-02/" title="零基础学-Java-02"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/%E9%9B%B6%E5%9F%BA%E7%A1%80%E5%AD%A6Java/Cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="零基础学-Java-02"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/09/23/%E9%9B%B6%E5%9F%BA%E7%A1%80%E5%AD%A6-Java-02/" title="零基础学-Java-02">零基础学-Java-02</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-09-23T00:55:55.000Z" title="发表于 2022-09-23 08:55:55">2022-09-23</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span></div><div class="content">类变量（静态变量）
该类的全体对象实例共享类变量

类变量在类加载的时候生成（生命周期随类加载开始，随着类消亡而销毁），即使没有创建对象实例也可通过类名.类变量名直接访问

类变量有默认初始化；但是一般进行显式初始化

可以用类名.类变量名直接访问（依然受访问修饰符的限制），如Child.count
Child child1 = new Child();Child child2 = new Child();// 两种访问方式，以下访问的均为同一个 countChild.count		// 推荐，类名.类变量名Child1.count	// 实例名.类变量名Child2.count	// 实例名.类变量名    class Child &#123;    // 两种定义方式都可，推荐第一种    public static int count;	// 推荐    static public int count;        // public static int count = 0;		// 一般进行显式初始化&#125;

类变量内存机制

类变量 == 静态变量 == 静态属性  ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/09/23/%E9%9B%B6%E5%9F%BA%E7%A1%80%E5%AD%A6-Java-01/" title="零基础学-Java-01"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/%E9%9B%B6%E5%9F%BA%E7%A1%80%E5%AD%A6Java/Cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="零基础学-Java-01"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/09/23/%E9%9B%B6%E5%9F%BA%E7%A1%80%E5%AD%A6-Java-01/" title="零基础学-Java-01">零基础学-Java-01</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-09-23T00:53:24.000Z" title="发表于 2022-09-23 08:53:24">2022-09-23</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Java/">Java</a></span></div><div class="content">基本数据类型及对应封装类byte——Byte（8bit）
short——Short（16bit）
int——Integer（32bit）
long——Long（64bit）
float——Float（32bit）
double——Double（64bit）
char——Character（16bit）
boolean——Boolean（1bit）
// 看基本数据类型长度用对应封装类的 SIZE 成员System.out.println(&quot;基本类型：byte 二进制位数：&quot; + Byte.SIZE);  

自动类型转换（小精度转大精度）char(16) - int(32) - long(64) - float(32) - double(64)
byte(8) - short(16) - int(32) - long(64) - float(32) - double(64)

有多种类型的数据混合运算时，系统自动首先将所有数据转化为容量最大的数据类型再进行计算
自动类型转换只能小转大，大转小会报错（只能强转）
(byte，short) 和 char 之间不会相互自动 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2020/08/17/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%A6%82%E4%BD%95%E8%AF%BB%E5%8F%96%E6%9C%AC%E5%9C%B0txt%E3%80%81json%E7%AD%89%E6%96%87%E4%BB%B6%E7%9A%84%E6%95%B0%E6%8D%AE(%E9%81%BF%E5%85%8D%E4%B9%B1%E7%A0%81)/" title="微信小程序如何读取本地txt、json等文件的数据(避免乱码)"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/Applet-Wechat/Applet%20of%20WeChat.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="微信小程序如何读取本地txt、json等文件的数据(避免乱码)"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/08/17/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%A6%82%E4%BD%95%E8%AF%BB%E5%8F%96%E6%9C%AC%E5%9C%B0txt%E3%80%81json%E7%AD%89%E6%96%87%E4%BB%B6%E7%9A%84%E6%95%B0%E6%8D%AE(%E9%81%BF%E5%85%8D%E4%B9%B1%E7%A0%81)/" title="微信小程序如何读取本地txt、json等文件的数据(避免乱码)">微信小程序如何读取本地txt、json等文件的数据(避免乱码)</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-08-17T00:53:01.000Z" title="发表于 2020-08-17 08:53:01">2020-08-17</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Applet/">Applet</a></span></div><div class="content">读取本地txt、json等文件的数据(避免乱码)

实现思路

选择文件
将文件上传到云存储
通过downloadFile获得文件路径tempFilePath
调用readFileSync根据步骤2的tempFilePath读取文件(不直接读取本地文件是因为微信小程序只能在特定目录下读取本地文件，且考虑到小程序的通用性)


1. 选择文件wx.chooseMessageFile
wx.chooseMessageFile(&#123;  count: 1,  type: &#x27;all&#x27;,  success(res) &#123;    console.log(&quot;选择文件成功&quot;, res)  &#125;,  fail(res) &#123;  	console.log(&quot;选择文件失败&quot;, res)  &#125;&#125;)

2. 将文件上传到云存储wx.cloud.uploadFile
wx.cloud.uploadFile(&#123;  cloudPath: res.tempFiles[0].name,  filePat ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2020/08/16/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8Fjs%E7%AB%AFfor%E5%BE%AA%E7%8E%AF%E4%B8%AD%E8%B0%83%E7%94%A8%E4%BA%91%E5%87%BD%E6%95%B0%E7%9A%84%E5%90%8C%E6%AD%A5%E9%97%AE%E9%A2%98/" title="微信小程序js端for循环中调用云函数的同步问题"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/Applet-Wechat/Applet%20of%20WeChat.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="微信小程序js端for循环中调用云函数的同步问题"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/08/16/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8Fjs%E7%AB%AFfor%E5%BE%AA%E7%8E%AF%E4%B8%AD%E8%B0%83%E7%94%A8%E4%BA%91%E5%87%BD%E6%95%B0%E7%9A%84%E5%90%8C%E6%AD%A5%E9%97%AE%E9%A2%98/" title="微信小程序js端for循环中调用云函数的同步问题">微信小程序js端for循环中调用云函数的同步问题</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-08-16T14:29:09.000Z" title="发表于 2020-08-16 22:29:09">2020-08-16</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Applet/">Applet</a></span></div><div class="content">js端for循环中调用云函数的同步问题
问题来源

微信小程序中for循环调用云函数从数据库中获取对应数据，由于云函数调用是异步的(在js中的for循环内部还可以顺序执行，在云函数中调用云函数就必须await了)，for循环的云函数调用还没执行完就执行for循环之后的内容

// batchIds中存放选中的ID，然后根据ID获取报名信息let that = thislet arr = []for (let i = 0; i &lt; that.data.batchIds.length; ++i) &#123;   wx.cloud.callFunction(&#123;     name: &quot;getSignUpRecordBySignUpId&quot;,     data: &#123;       _id: that.data.batchIds[i]     &#125;,     success: res =&gt; &#123;       console.log(&#x27;根据_id获取报名信息成功&#x27;, res)       arr.push(res. ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2020/08/07/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%BB%8E%E4%BA%91%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E9%87%8D%E5%91%BD%E5%90%8D%E5%B9%B6%E4%BF%9D%E5%AD%98%E5%88%B0%E6%89%8B%E6%9C%BA/" title="微信小程序从云数据库中下载文件重命名并保存到手机"><img class="post_bg" src="https://study-record-images.oss-cn-beijing.aliyuncs.com/Java/Applet-Wechat/Applet%20of%20WeChat.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="微信小程序从云数据库中下载文件重命名并保存到手机"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/08/07/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%BB%8E%E4%BA%91%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E9%87%8D%E5%91%BD%E5%90%8D%E5%B9%B6%E4%BF%9D%E5%AD%98%E5%88%B0%E6%89%8B%E6%9C%BA/" title="微信小程序从云数据库中下载文件重命名并保存到手机">微信小程序从云数据库中下载文件重命名并保存到手机</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-08-07T14:48:37.000Z" title="发表于 2020-08-07 22:48:37">2020-08-07</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Applet/">Applet</a></span></div><div class="content">重命名并保存文件到手机

下载wx.cloud.downloadFile
保存并重命名wx.getFileSystemManager().saveFile，此时保存到微信固定的文件夹，手机端很不友好，这一步骤重点是利用filePath重命名如下filePath: wx.env.USER_DATA_PATH + &quot;/&quot; + &#39;保存文件的名字&#39; + &#39;.保存文件的格式&#39;,

wx.getFileSystemManager().saveFile(&#123;  tempFilePath: sres.tempFilePath, // 传入一个本地临时文件路径, http://tmp/开头的  filePath: wx.env.USER_DATA_PATH + &quot;/&quot; + that.data.gameTitle + &#x27;.xlsx&#x27;, //此处文件名自定义，因为tempFilePath对应的是一大长串字符  success(tres) &#123;    console.log(&#x27;保存excel成 ...</div></div></div><nav id="pagination"><div class="pagination"><a class="extend prev" rel="prev" href="/page/3/#content-inner"><i class="fas fa-chevron-left fa-fw"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/3/#content-inner">3</a><span class="page-number current">4</span><a class="page-number" href="/page/5/#content-inner">5</a><a class="extend next" rel="next" href="/page/5/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://s2.loli.net/2022/09/22/36LN4kcjYOd9HT8.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">zcm</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">43</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div></div><div class="sticky_layout"><div class="card-widget card-categories"><div class="item-headline">
            <i class="fas fa-folder-open"></i>
            <span>分类</span>
            
            </div>
            <ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Algorithm/"><span class="card-category-list-name">Algorithm</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Android/"><span class="card-category-list-name">Android</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Applet/"><span class="card-category-list-name">Applet</span><span class="card-category-list-count">4</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/DataBase/"><span class="card-category-list-name">DataBase</span><span class="card-category-list-count">3</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Java/"><span class="card-category-list-name">Java</span><span class="card-category-list-count">11</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Others/"><span class="card-category-list-name">Others</span><span class="card-category-list-count">7</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Spring/"><span class="card-category-list-name">Spring</span><span class="card-category-list-count">8</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Tips/"><span class="card-category-list-name">Tips</span><span class="card-category-list-count">2</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/"><span class="card-category-list-name">中间件</span><span class="card-category-list-count">2</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/"><span class="card-category-list-name">大数据</span><span class="card-category-list-count">4</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E9%9D%A2%E7%BB%8F/"><span class="card-category-list-name">面经</span><span class="card-category-list-count">14</span></a></li>
            </ul></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span><a class="card-more-btn" href="/archives/" title="查看更多">
    <i class="fas fa-angle-right"></i></a></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/05/"><span class="card-archive-list-date">五月 2023</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/04/"><span class="card-archive-list-date">四月 2023</span><span class="card-archive-list-count">3</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/03/"><span class="card-archive-list-date">三月 2023</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/12/"><span class="card-archive-list-date">十二月 2022</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/11/"><span class="card-archive-list-date">十一月 2022</span><span class="card-archive-list-count">3</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/10/"><span class="card-archive-list-date">十月 2022</span><span class="card-archive-list-count">16</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/09/"><span class="card-archive-list-date">九月 2022</span><span class="card-archive-list-count">11</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2020/08/"><span class="card-archive-list-date">八月 2020</span><span class="card-archive-list-count">4</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">43</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2023-05-18T11:46:04.550Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总字数 :</div><div class="item-count">508.4k</div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2023-05-18T11:46:04.703Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2023 By zcm</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"></div><script src="/js/categories.js?v1"></script><script src="/js/navigation.js?v1"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>